attend_record_fake_records=[
        		{empid:'AE1856',name:'何宇林',date:'2016-01-12',enter_time:'08:13',
        		leave_time:'17:51',late:'',late_team:'',workspan:'08:30',overtime:'00:00'},
        		{empid:'AE1857',name:'白联军',date:'2016-01-11',enter_time:'08:12',leave_time:'17:52',
        		late:'',late_team:'',workspan:'08:30',overtime:'00:00'}
       ]


app.controller('attend_record_controller',function ($scope,$http,$filter,$sessionStorage,headFilterManager) {
	
	$scope.heads=[{name:'empid',label:'员工号',filter:true},
				{name:'name',label:'姓名',},
				{name:'date',label:'日期',filter:true},
				{name:'enter_time',label:'第一次打卡时间'},
				{name:'leave_time',label:'最后打卡时间'},
				{name:'late',label:'迟到',filter:true},
				{name:'late_team',label:'团队迟到时间'},
				{name:'late_person',label:'个人迟到时间'},
				{name:'workspan',label:'工作时长'},
				{name:'overtime',label:'加班时间'},
				{name:'absent',label:'旷工'}
					]

	// 过滤器显示设置
	$scope.head_order='id';
	$scope.hello=function () {
		alert('hello')
	}
	$scope.namechanged=function (file) {
		$scope.filename=file.name;
	}
	$scope.fb={
		show:{
			keywords:true,
			workday:true,
			restday:true
		},
		workday:true,
		restday:true
	}
	$scope.uploading=false;
	$scope.upload_record=function (file) {
		//myfile.upload("/attendance/upload/record/")
		pro=file.upload("/attendance/upload/record/")
		pro.success(function () {
			alert('上传考勤记录成功')
		}).error(function(data, status, headers, config) {
			alert('error '+status)
		}) 
	}

	$scope.currentPage=0;
    $scope.itemsPerPage=23;

       
  	if(is_local){
        $scope.org_records=attend_record_fake_records

       $scope.search=function (start_date,end_date) {
			alert(start_date)
			alert(end_date)
		}
    }else{
	    $scope.org_records=[];
    }
    $scope.records=$scope.org_records;

	// -----------为了头部过滤------------
	var hfmanagr=new headFilterManager.HFManager()
	hfmanagr.initHeads($scope.heads)
	$scope.$on('head_filter_changed',function (even,filter) {
		if(hfmanagr.has_filter(filter)){
			//$scope.records=$scope.funlist_filter($scope.org_records)
			$scope.records=hfmanagr.filter($scope.org_records)
		}
	})
	//-某个头部排序，通知其他排序变为'不排序'
	$scope.$on('sortClick',function (even,name) {
		$scope.$broadcast('otherSortClick',name);
	})
	//$scope.filterList=[]
	//for(x in $scope.heads.fields){
	//	if($scope.heads.fields[x].filter){
	//		$scope[$scope.heads.fields[x].name+'_filter']={}
	//		$scope.heads.fields[x].filter=$scope[$scope.heads.fields[x].name+'_filter']
	//		$scope.filterList.push($scope.heads.fields[x].filter)
	//	}
	//}
	//$scope.$on('headFilter',function(event,filter){
	//	$scope.records=funlist_filter($scope.org_records,$scope.filterList);
	//	$scope.currentPage=0;
	//})
	//----------------------------------


    
	$scope.search=function (start_date,end_date,fb) {
		var leave=$scope.leave;
		var post_data = {
				attend_record:{start_date:start_date,end_date:end_date,
								keyword:fb.keywords,workday:fb.workday,restday:fb.restday
								},
			}; 
		$scope.fb.uploading=true;
		$http.post(post_url,post_data)
		.success(function(data, status, headers, config) { 
			$scope.org_records=data.attend_record.records;
			$scope.records=$scope.org_records;
			$scope.currentPage=0;
			$scope.fb.uploading=false;
		}).error(function(data, status, headers, config) {  
		    alert('有错误,返回码为:'+status)
		    $scope.fb.uploading=false;
		});
		}
    $scope.$on("$routeChangeStart", function() {
   		$sessionStorage.haha='jjjjjj'
  	})
  	if($sessionStorage.haha){
	  	alert($sessionStorage.haha);
  	}
}
)